package com.dms.service.impl;

import com.dms.mapper.OtherManageMapper;
import com.dms.pojo.LevelOneMenu;
import com.dms.pojo.LevelTwoMenu;
import com.dms.service.OtherManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * @className: OtherManageServiceImpl
 * @package: com.dms.service.impl
 * @description 一些其他需要调用后台的功能的业务逻辑层接口实现类
 * @author: sk
 */
@Service
public class OtherManageServiceImpl implements OtherManageService {

    @Autowired
    OtherManageMapper otherManageMapper;

    /**
     * 根据用户类型获取菜单栏
     * @param userType
     * @return
     */
    @Override
    public List<LevelOneMenu> getMenuList(Integer userType) {
        List<LevelOneMenu> levelOneMenuList = otherManageMapper.getMenuList(userType);
        //前一个对象
        LevelOneMenu levelOneMenu = null;
        Iterator<LevelOneMenu> it = levelOneMenuList.iterator();
        while (it.hasNext()) {
            //当前对象
            LevelOneMenu menu = it.next();
            //如果前后不一致，则到下次循环
            if (levelOneMenu == null || menu.getMenuNumber() != levelOneMenu.getMenuNumber()) {
                levelOneMenu = menu;
                continue;
            } else {
                //赋值
                for (LevelTwoMenu levelTwoMenu : menu.getLevelTwoMenuList()) {
                    levelOneMenu.getLevelTwoMenuList().add(levelTwoMenu);
                }
                //删除当前同样的菜单对象
                it.remove();
            }
        }
        return levelOneMenuList;
    }

    /**
     * 修改密码
     * @param userName
     * @param password
     * @return
     */
    @Override
    public int editPassword(String userName, String password) {
        System.out.println(password);
        return otherManageMapper.editPassword(userName, password);
    }
}
